﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using WorkFlowBLL;
using EntityBLL;
using DataContext;

namespace QLCF.Forms.Reports
{
    public partial class frmStockReport : Form
    {
        public frmStockReport()
        {
            InitializeComponent();
            GetListCategory();
            LoadData();
        }
        private int CateID = -1;
        private string CateName = "Tất cả";
        public void LoadData()
        {
            lstViewReportStock.Items.Clear();
            CtrBase ctrBase = new CtrBase();
            try
            {
                uspCategoryGetAllResult item = (uspCategoryGetAllResult)cbxCategory.SelectedItem;
                CateID = item.CategoryID;
                CateName = item.CategoryName;
            }
            catch
            {
                CateID = -1;
                CateName = "Tất cả";
            }
            var lstItem = ctrBase.GetAllReportStockSearch(txtProductName.Text.Trim(), CateID);
            int i = 1;
            foreach (var item in lstItem)
            {
                ListViewItem item1 = new ListViewItem((i++).ToString());
                item1.SubItems.Add(item.ProductName);
                item1.SubItems.Add(item.CategoryName);
                item1.SubItems.Add(item.CurrentQuantityName);
                item1.SubItems.Add(item.TotalStockName);
                item1.Tag = item.ProductID;
                lstViewReportStock.Items.Add(item1);
            }
        }

        private void GetListCategory()
        {
            CtrCategory ctrCategory = new CtrCategory();
            var objCategory = ctrCategory.GetListCategory();
            DataContext.uspCategoryGetAllResult obj = new DataContext.uspCategoryGetAllResult();
            obj.CategoryID = -1;
            obj.CategoryName = "Tất cả";
            objCategory.Insert(0, obj);
            cbxCategory.DataSource = objCategory;
            cbxCategory.DisplayMember = "CategoryName";
            cbxCategory.ValueMember = "CategoryID";
            cbxCategory.SelectedIndex = 0;
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            this.LoadData();
        }

        private void btnPrint_Click(object sender, EventArgs e)
        {
            Reports.frmViewReportStock frmS = new frmViewReportStock(CateID, CateName);
            frmS.ShowDialog();
        }
    }
}
